package com.mofum.cloud.core.model.impl;

import com.mofum.cloud.core.error.runtime.RuntimeContextException;
import com.mofum.cloud.core.model.RuntimeContext;

import java.util.concurrent.ConcurrentHashMap;

/**
 * 内存环境变量实现
 * ===================================================================
 * <p> 内存环境变量实现,提供内存部分的运行上下文支持
 * ===================================================================
 *
 * @author yumi@omuao.com
 */
public class MemoryRuntimeContextImpl extends ConcurrentHashMap<String, Object> implements RuntimeContext {

    @Override
    public void putVariable(String key, Object value) throws RuntimeContextException {
        if (getVariable(key) != null) {
            throw new RuntimeContextException(key + " ：环境变量已存在！");
        }
        this.put(key, value);
    }

    @Override
    public Object getVariable(String key) {
        return this.get(key);
    }
}
